package gam.n1.achievement.n;


import gam.n1.achievement.iAchievement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;
import java.util.function.Supplier;

public abstract class BaseAchievement<T> implements iAchievement<T> {


    protected T $t;
    protected Supplier<T> valueF;
    protected String name;
    public BaseAchievement(@NotNull Supplier<T> initValue, @Nullable String name){
        this.$t = initValue.get();
        if (name != null ) this.name = name;
    }

    @Override
    public void r() {
        $t = valueF.get();
    }

    @Override
    public String name() {
        return name;
    }

    @Override
    public T get() {
        return $t;
    }

    @Override
    public void set(Supplier<T> s) {
        if (s != null) $t = s.get();
    }

    @Override
    public void up(Function<T, T> f) {
        set(f.apply(get()));
    }

}
